<template>
  <el-container class="page">
    <!-- 侧边栏 -->
    <el-aside width="200px">
      <!-- 
      default-active:默认激活，选的是每一个导航的index 
      background-color:背景色
      text-color:文字颜色
      active-text-color：激活文字的颜色
      unique-opened	：是否只保持一个子菜单的展开
      router:是否使用 vue-router 的模式，启用该模式会在激活导航时以 index 作为 path 进行路由跳转
       -->

      <el-menu
        default-active="1-3"
        class="el-menu-vertical-demo"
        text-color="#fff"
        active-text-color="#ffd04b"
        unique-opened
        router
      >
        <el-menu-item index="/">
          <i class="el-icon-menu"></i>
          <span slot="title">首页</span>
        </el-menu-item>

        <!-- div遍历 -->
        <div v-for="item in info.menus"  :key="item.id">
          <!-- 目录循环 -->
          <el-submenu v-if="item.children"  :index="item.id+''">
            <template slot="title">
              <i :class="item.icon"></i>
              <span>{{ item.title }}</span>
            </template>
            <el-menu-item-group>
              <el-menu-item
                v-for="i in item.children"
                :key="i.id"
                :index="i.url"
                >{{ i.title }}</el-menu-item
              >
            </el-menu-item-group>
          </el-submenu>

          <!-- 菜单的循环 -->
          <el-menu-item  v-else :index="item.url">
            <i class="el-icon-s-promotion"></i>
            <span slot="title">{{ item.title }}</span>
          </el-menu-item>
        </div>
      </el-menu>
    </el-aside>
    <el-container>
      <!-- 头部 -->
      <el-header>
        <div class="header-con">
          <span>{{ info.username }}</span>
          <el-button type="info" @click="logout">退出登录</el-button>
        </div>
      </el-header>
      <el-main>
        <!-- 面包屑 -->
        <el-breadcrumb
          separator-class="el-icon-arrow-right"
          v-if="$route.meta.title"
        >
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>{{ $route.meta.title }}</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 二级路由出口 -->
        <router-view class="view"></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
import {} from "../../http/api";
import { mapGetters, mapActions } from "vuex";
export default {
  components: {},
  props: [],
  data() {
    return {};
  },
  methods: {
    ...mapActions({
      changeInfo: "changeInfo",
    }),
    //退出登录
    logout() {
      this.changeInfo({});
      this.$router.replace("/login");
    },
  },
  mounted() {},
  computed: {
    // 3.从vuex中取出info
    ...mapGetters({
      info: "info",
    }),
  },
  watch: {},
};
</script>
<style scoped lang="less">
@import "../../less/index.less";
/deep/.el-menu {
  background: @middle !important;
}
/deep/.el-submenu__title:hover,
/deep/.el-menu-item:focus,
/deep/.el-menu-item:hover {
  background: @light !important;
}
.el-aside {
  background: @middle;
}
.el-header {
  background: @light;
}
.page {
  height: 100vw;
}
.header-con {
  float: right;
}
.header-con span {
  margin-top: @margin;
  margin-right: @margin;
  color: #fff;
}
.header-con .el-button {
  margin-top: @margin;
}
.view {
  padding-top: @padding;
}
</style>